#include<iostream>
#include<vector>
#include "Frame.h"

#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
    
using namespace std;
 
     /* Flag set by ‘--verbose’. */
static int verbose_flag;

void usage() {
	cout << "add_source -r <RA deg> -d <Dec deg> -p <pol> -f <flux> " << endl;
}

int main (int argc, char **argv) {


	int poln=0;
	float scale = 0.;
	float ra_deg=0., dec_deg=0.,flux=10,width=0.01;
	vector<char *> filenames;
        char *device;	
        char c;
	while (1)
	{
		static struct option long_options[] =
		{
			/* These options set a flag. */
			{"verbose", no_argument,       &verbose_flag, 1},
			{"brief",   no_argument,       &verbose_flag, 0},
			/* These options don't set a flag.
			   We distinguish them by their indices. */
			{"ra",  optional_argument,      0, 'r'},
			{"dec",  optional_argument,       0, 'd'},
			{"fluxd",  optional_argument, 0, 'f'},
			{"device",optional_argument, 0, 'D'},
			{"poln",  optional_argument, 0, 'p'},
			{"scale" ,optional_argument, 0, 's'},
			{"width", optional_argument,0,'w'},
			{"help",no_argument,0,'h'},			
			{0, 0, 0, 0}
		};
		/* getopt_long stores the option index here. */
		int option_index = 0;

		c = getopt_long (argc, argv, "hr:d:D:p:s:w:",
				long_options, &option_index);

		/* Detect the end of the options. */
		if (c == -1)
			break;

		switch (c)
		{
			case 0:
				/* If this option set a flag, do nothing else now. */
				if (long_options[option_index].flag != 0)
					break;
				printf ("option %s", long_options[option_index].name);
				if (optarg)
					printf (" with arg %s", optarg);
				printf ("\n");
				break;
			case 'f':
				flux = atof(optarg);
				break;
			case 'w':
				width = atof(optarg);
				break;
			case 'p':
				poln = atoi(optarg);
				break;
			case 's':
				scale = atof(optarg);
				break;
			case 'r':
				ra_deg = atof(optarg);
				break;

			case 'd':
				dec_deg = atof(optarg);;
				break;
			case 'D':
				device = strdup(optarg);
				break;
			case 'h':
				usage();
				abort ();
				/* getopt_long already printed an error message. */
				break;

			default:
				abort ();
		}
	}
	if (optind < argc)
	{
           printf ("non-option ARGV-elements: ");
	   while (optind < argc)
		   filenames.push_back(strdup(argv[optind++]));
	}

	for (unsigned int i = 0; i < filenames.size() ; i++ ) {

		Frame Framefile((char *) filenames[i]);
		if (scale != 0) {
			Framefile.Data->Scale(scale);
		}
		Framefile.Data->set_poln(poln);
		Framefile.Data->add_point(ra_deg,dec_deg,flux,width);
	}
	exit(EXIT_SUCCESS);
}


